package com.laamella.syntherface.synths.models;

import javax.sound.midi.InvalidMidiDataException;

import com.laamella.syntherface.synths.midi.MidiInterface;

@SuppressWarnings("serial") public abstract class ParameterModelWithMidiInterface extends ParameterModel {

	private final MidiInterface midiInterface;

	public ParameterModelWithMidiInterface(String name, int initialValue, MidiInterface midiInterface, ParameterType type) {
		super(name, initialValue, type);
		if (midiInterface == null) {
			throw new RuntimeException("MIDI interface is null");
		}
		this.midiInterface = midiInterface;
	}

	public ParameterModelWithMidiInterface(String name, MidiInterface midiInterface) {
		this(name, 0, midiInterface, ParameterType.OnOff);
	}

	public MidiInterface getMidiInterface() {
		return midiInterface;
	}

	@Override protected void updateSynthesizer(int newValue) throws InvalidMidiDataException {
		updateSynthesizer(getMidiInterface(), newValue);
	}

	protected abstract void updateSynthesizer(MidiInterface midiInterface, int value) throws InvalidMidiDataException;
}
